{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Labeling: Raw Returns\n",
    "\n",
    "![image_example](img/Raw_returns_distribution.png)\n",
    "_*Fig. 1:*_ Distribution of daily logarithmic returns for MSFT between Jan 2010 and May 2020.\n",
    "\n",
    "\n",
    "## Abstract\n",
    "\n",
    "Labeling data by raw returns is the most simple and basic method of labeling financial data for machine learning. Raw returns can be calculated either on a simple or logarithmic basis. Using returns rather than prices is usually preferred for financial time series data because returns are usually stationary, unlike prices. This means that returns across different assets, or the same asset at different times, can be directly compared with each other. The same cannot be said of price differences, since the magnitude of the price change is highly dependent on the preceding price, which varies with time.\n",
    "\n",
    "\n",
    "## How it works\n",
    "\n",
    "The simple raw return for an observation with\n",
    "price $p_t$ at time $t$ relative to its price at time $t-1$ is as follows:\n",
    "\n",
    "$$\n",
    "    r_t = \\frac{p_{t}}{p_{t-1}} - 1\n",
    "$$\n",
    "\n",
    "The logarithmic return is:\n",
    "\n",
    "$$\n",
    "    r_t = log(p_t) - log(p_{t-1})\n",
    "$$\n",
    "\n",
    "If categorical labels are desired:\n",
    "\n",
    "$$\n",
    "     \\begin{equation}\n",
    "     \\begin{split}\n",
    "       L_{t} = \\begin{cases}\n",
    "       -1 &\\ \\text{if} \\ \\ r_t < 0\\\\\n",
    "       0 &\\ \\text{if} \\ \\ r_t = 0\\\\\n",
    "       1 &\\ \\text{if} \\ \\ r_t > 0\n",
    "       \\end{cases}\n",
    "     \\end{split}\n",
    "     \\end{equation}\n",
    "$$\n",
    "\n",
    "If desired, the user can specify a resampling period to apply to the price data prior to calculating returns. The user\n",
    "can also lag the returns to make them forward-looking.\n",
    "\n",
    "---\n",
    "## Examples of use"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import yfinance as yf\n",
    "\n",
    "from mlfinlab.labeling import raw_return\n",
    "\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2010-01-04    24.23\n",
       "2010-01-05    24.23\n",
       "2010-01-06    24.09\n",
       "2010-01-07    23.84\n",
       "2010-01-08    24.00\n",
       "Name: Close, dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load price data\n",
    "msft = yf.Ticker('MSFT')\n",
    "msft_df = msft.history(start='2010-1-1', end ='2020-5-18')\n",
    "\n",
    "# Subset closing prices\n",
    "close = msft_df['Close']\n",
    "close.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Daily returns on a stock"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The data provided is already in daily close prices, so no resampling is needed. We can plot the distribution of logarithmic returns for MSFT stock from 2010-2020."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, 'Daily Log Return')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZwdVZn/8c+XsEUaCQhGCEjDGBmRCEKDzDgOHRZFEYH5ueAgEEQzjjLqmJkhiAouOLggLjhiFJBFjYALEdwAbdGfIhAGCItIhAhZDIsk0BDAhGf+OKdJ5XK7u6q76/btzvf9et3XvbU/p6rufeqcqluliMDMzKysDUY7ADMzG1ucOMzMrBInDjMzq8SJw8zMKnHiMDOzSpw4zMyskjGdOCSdLenD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/T8j0+SEstVwO2kp98N5lPAcblJ6r1Al9JTJW8nnRQH+CFwRN/JceBrpCR1Ham2VKasZsPiu+OaAZK6SCedR+QxppI6IqI31zi+D5wbEd8fiXmbjTbXOGy9J2k26ZGyJ43gbE+VdBPpGS33AD8YwXmbjSrXOMzMrBLXOMzMrBInDjMzq8SJw8zMKnHiMDOzSpw4zMyskv8DH64mg9xbTFsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "returns1 = raw_return(prices=close, logarithmic=True, lag=False)\n",
    "ax = returns1.hist(bins=100)\n",
    "ax.set_title(\"Distribution of Daily Log Returns on MSFT From 2010-2020\")\n",
    "ax.set_ylabel(\"Frequency\")\n",
    "ax.set_xlabel(\"Daily Log Return\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also get categorical labels. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       " 1.0    1358\n",
       "-1.0    1219\n",
       " 0.0      32\n",
       "Name: Close, dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "returns2 = raw_return(close, logarithmic=True, binary=True, lag=False)\n",
    "returns2.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that over this time period, MSFT had a positive daily return about 52% of the time and a negative daily return about 47% of the time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Resampling by week"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Suppose we would rather calculate forward returns per week instead of per day. Then we would need to resample."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, 'Weekly Log Return')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY8AAAEWCAYAAACe8xtsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZwdVZ338c9XQEAaWQy2EIHAiCAQiNIuj9t0xIVV8dEBHUVQJI77jJkZURBxR0d0xmd0AEU2ByKoCAMMGJFmE4QEgRBBQYgCgSBbSGMEA7/nj3MuVC63+1Z137q3u/N9v1796lvbqXOq6tavzqlzqxQRmJmZVfGMXmfAzMwmHwcPMzOrzMHDzMwqc/AwM7PKHDzMzKwyBw8zM6tswgQPScdK+kyH0tpK0rCktfLwkKT3dyLtnN7/SjqoU+lVWO8XJd0n6Z5ur7spHydJ+mLVaWY2dXQleEhaImmlpBWSHpL0S0n/IOnJ9UfEP0TEF0qm9frR5omIP0ZEX0Q83oG8HyXpB03p7xkRJ4837Yr52BKYC+wYEc9rMf23kvYvDL9KUrQYNyxp7e7kujxJg5Lu7MJ6GsfisKR7crDrm0h57LZcrpD0k6bxu+bxQ4Vxb5F0naSH84XMRZJm5GlHSfpr3raNv3+VtLgw/LikvxSGP90iPy3TqXkzPI2kdSWdIOkP+dz1a0l7Ns2zu6SbJf1Z0sWSti5M2z+f6/5c3IaF6bMkLczTF0qaNUpeXiFpvqQHJP1J0pmSNi9Ml6SvSro//31NkvK0F0o6Oy/3gKQLJW3flP4/5e/Dcknfl7Ruu+3TzZrHvhGxIbA1cDTwSeCETq9kIp4YO2Rr4P6IuHeE6ZcCf1sYfi1wc4txv4yIVfVkcdLYNyL6gFnAi4FPdWOlE/zY/BPwSknPKYw7CPhdY0DSC4BTSBcxGwHbAN8Bnigs88N84db4+1pE7NQYBi4DPlKY/uUR8vO0dJ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ZV5nguB90nqA5A0Xen95RcBb8+fG+9I3zovE6QaxQ5q8f7n7HvAt4Br8nrLuBmYIekFefhAUnC6GdhWT72v/IB2CeXay1dI74xplPOjUnrJlaQX5/ErgA0Liy4BXpLneQnplbZmXeHgYRPFIlIvq6uaxi2PiPsAIuJnwGnAlZIWkV6HumFE/AY4AvhZbgaaD2zeSCQiHic9ynq2pA81rzgiFpJqOCeOkr/dJd3Z+CP1kHovcGbOyxOkd3yvJL3v+wJJlwPLSG/da+dY4LVKj2j/Aqm57YbcpfgLeZ6LgR0bN8xJL8LaNDdvfZD05FWzrvBTdW2NJ2kL0r2FHSJi3O+BltQXEcO55vBt4JaI+OZ40zWbSFzzsDWapPeQenYd3onAkR2aawOLSW/cO67N/GaTjmseZmZWmWseZmZWmYOHmZlV5uBhZmaVOXiYmVllDh5mZlbZ/wfbSsrFJKpG3QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "returns3 = raw_return(prices=close, logarithmic=True, resample_by='W', lag=True)\n",
    "ax2 = returns3.hist(bins=100)\n",
    "ax2.set_title(\"Distribution of Weekly Log Returns on MSFT From 2010-2020\")\n",
    "ax2.set_ylabel(\"Frequency\")\n",
    "ax2.set_xlabel(\"Weekly Log Return\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       " 1.0    312\n",
       "-1.0    224\n",
       " 0.0      4\n",
       "Name: Close, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "returns4 = raw_return(prices=close, binary=True, logarithmic=True, resample_by='W', lag=True)\n",
    "returns4.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "## Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook presents the raw returns labeling method, which is the most basic and ubiquitous method used in financial data analysis, and is generally superior to using price changes. In this method, simple or logarithmic returns can be outputted based on price data. This labeling method is often a precursor to more sophisticated labeling methods."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## References"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Coqueret, G. and Guida, T., 2020. Machine Learning For Factor Investing."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
